#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：PythonProjects
@File    ：find_card.py
@IDE     ：PyCharm
@Author  ：pipibao
@Date    ：2021/7/5 下午3:22
'''

import cv2 as cv
import op


def find_card(path):
    name = path[path.rfind('/') + 1:]
    print(path)
    img = cv.imread(path)
    # cv.imshow("src", img)
    # cv.waitKey(0)
    img = op.resize(img)
    img = op.shift_filter(img)
    hsv_low, hsv_high = op.hsv_color_room("blue")
    img_blue = op.check_color(img, hsv_low, hsv_high)
    t = op.open_operate(img_blue, 3, 3)
    t = op.close_operate(t, 5, 5)
    res = img.copy()
    squares, res = op.find_squares(t, res)
    for i in squares:
        flag, res = op.cut_image(img, i)
        if flag is None:
            continue
        res = op.check_color(res, hsv_low, hsv_high)
    # cv.imshow("res", res)
    cv.imwrite("Image/car_id/" + name, res)
    # cv.waitKey(0)
    # cv.destroyAllWindows()
    return name


if __name__ == '__main__':
    find_card("Image/test/1.jpeg")
